<script lang="ts" setup>
interface Props {
  appear?: boolean;
  message?: string;
  radio?: string;
  maxCount?: number;
  bgColor?: string;
  color?: string;
}
const props = withDefaults(defineProps<Props>(), {
  maxCount: 500,
  appear: true,
  bgColor: "#ffffff",
  color: "#333333"
});
</script>
<template>
  <Transition name="fade" :appear="props.appear">
    <view class="bubble user-bubble">
      <view class="text" :style="{ backgroundColor: bgColor, color }">
        {{ props.message }}
      </view>
    </view>
  </Transition>
</template>
<style lang="scss" scoped>
.bubble {
  position: relative;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-top: 40rpx;
  .text {
    font-size: 28rpx;
    padding: 15rpx 24rpx;
    border-radius: 20rpx;
    border-top-right-radius: 0;
    background: var(--bg-user-bubble);
  }
}

.transition {
  width: 100%;
}
/* 1. 声明过渡效果 */
.fade-move,
.fade-enter-active,
.fade-leave-active {
  transition: all 0.5s cubic-bezier(0.55, 0, 0.1, 1);
}

/* 2. 声明进入和离开的状态 */
.fade-enter-from,
.fade-leave-to {
  opacity: 0;
  transform: translate(0, 30px);
}

/* 3. 确保离开的项目被移除出了布局流
      以便正确地计算移动时的动画效果。 */
.fade-leave-active {
  position: absolute;
}
</style>
